//
//  LSZStudyPlanViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/23.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZStudyPlanViewController.h"

@interface LSZStudyPlanViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong) UICollectionView * collectionViewStudyPlan;
@property(nonatomic,strong) LSZLearningCatalogueManager * learningCatalogueManager ;
@end

@implementation LSZStudyPlanViewController
#pragma mark - 获取数据
-(void)getDataStudyPlan
{
    [LSZRequestDicData obtainStudyPlanDetails:^(BOOL isOk, NSString * string, LSZLearningCatalogueManager * LearningCatalogueManager) {
        if (isOk == YES) {
            self.learningCatalogueManager = LearningCatalogueManager;
            [self.collectionViewStudyPlan reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZStudyPlanViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"课程计划";
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZStudyPlanViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];

    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumInteritemSpacing = 0.5;
    flowLayout.minimumLineSpacing = 0.5;
    flowLayout.itemSize = CGSizeMake(ScreenWidth-20,200);
    flowLayout.sectionInset = UIEdgeInsetsMake(10,10,10, 10);//分别为上、左、下、右
    self.collectionViewStudyPlan = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) collectionViewLayout:flowLayout];
    self.collectionViewStudyPlan.dataSource = self;
    self.collectionViewStudyPlan.delegate = self;
    self.collectionViewStudyPlan.backgroundColor = RGBColor(236, 236, 236);
    //添加以下代码关闭估算行高
    [self.view addSubview:self.collectionViewStudyPlan];
    [self.collectionViewStudyPlan registerClass:[LSZStudyPlanCollectionViewCell class] forCellWithReuseIdentifier:@"LSZStudyPlanCollectionViewCell"];
    [self getDataStudyPlan];
}
#pragma mark - 设置有几个区
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return self.learningCatalogueManager.mutMgArray.count;
}
#pragma mark - 设置每个区有几个
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    // 定义的轮播器视图
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LSZStudyPlanCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZStudyPlanCollectionViewCell" forIndexPath:indexPath];
    LSZLearningCatalogueMg * mg = nil;
    mg = self.learningCatalogueManager.mutMgArray[indexPath.section];
    cell.learningCatalogueMg = mg;
    return cell;
}
#pragma mark - 点击进入详情页
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.learningCatalogueManager.mutMgArray.count > indexPath.section) {
        LSZLearningCatalogueMg * mg = nil;
        mg = self.learningCatalogueManager.mutMgArray[indexPath.section];
        LSZSecondaryLiteratureDetailsVC * vc = [[LSZSecondaryLiteratureDetailsVC alloc]init];
        vc.id_id = mg.id_id;
        vc.urlImageView = mg.coverUrl;
        vc.titleString = mg.name;
        [self.navigationController pushViewController:vc animated:YES];
//        LSZDirectoryDetailsViewController * vc = [[LSZDirectoryDetailsViewController alloc]init];
//        vc.productID = mg.id_id;
////        vc.url = [NSString stringWithFormat:@"%@%@",URLTotal,mg.contentUrl];
//        vc.imageViewStr = [NSString stringWithFormat:@"%@%@",URLTotal,mg.coverUrl];
//        vc.titleStr = mg.name;
//        vc.publishTime = mg.publishTime;
//        vc.period = @"20";
//        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
